﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;
using System.Collections.Generic;//Please add references
namespace EnterpriseFund.DAL
{
    /// <summary>
    /// 数据访问类:AllowanceFile
    /// </summary>
    public partial class AllowanceFile
    {
        public AllowanceFile()
        { }
        #region  BasicMethod
        /// <summary>
        /// 增加文件
        /// </summary>
        /// <param name="enList"></param>
        /// <param name="model"></param>
        public string Add(List<Model.AllowanceFileEntry> enList, Model.AllowanceFile model, string issueIDList)
        {
            StringBuilder strSql = new StringBuilder();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();

            var getBillIdSql = "exec sp_getbillno 'fund.t_AllowanceFile','FAllowanceFileID','','','',@returnBId output ";
            var getBillIdPar = new SqlParameter[]{ 
                new SqlParameter("@returnBId", SqlDbType.NVarChar, 50)
            };

            getBillIdPar[0].Direction = ParameterDirection.Output;

            cmds.CommandText = getBillIdSql.ToString();
            cmds.Parameters = getBillIdPar;
            cmdList.Add(cmds);

            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("insert into fund.t_AllowanceFile(");
            strSql.Append("FAllowanceFileID,FPeriod,FFileName,FNote,FEntityNo,FInsEmpNo,FInsDeptNo,FInsDate,FInsIP,FFinancePropNo,FYear,FStatus)");
            strSql.Append(" values (");
            strSql.Append("@returnBId,@FPeriod,@FFileName,@FNote,@FEntityNo,@FInsEmpNo,@FInsDeptNo,@FInsDate,@FInsIP,@FFinancePropNo,@FYear,@FStatus)");
            SqlParameter[] parameters = {
					new SqlParameter("@returnBId", SqlDbType.NVarChar,50),
					new SqlParameter("@FPeriod", SqlDbType.Int,4),
					new SqlParameter("@FFileName", SqlDbType.NVarChar,255),
					new SqlParameter("@FNote", SqlDbType.NVarChar,255),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FInsEmpNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FInsDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FInsDate", SqlDbType.DateTime),
					new SqlParameter("@FInsIP", SqlDbType.NVarChar,15),
					new SqlParameter("@FFinancePropNo", SqlDbType.NVarChar,6),
					new SqlParameter("@FYear", SqlDbType.Decimal,5),
					new SqlParameter("@FStatus", SqlDbType.NVarChar,6)};
            parameters[0].Direction = ParameterDirection.InputOutput;
            parameters[1].Value = model.FPeriod;
            parameters[2].Value = model.FFileName;
            parameters[3].Value = model.FNote;
            parameters[4].Value = model.FEntityNo;
            parameters[5].Value = model.FInsEmpNo;
            parameters[6].Value = model.FInsDeptNo;
            parameters[7].Value = model.FInsDate;
            parameters[8].Value = model.FInsIP;
            parameters[9].Value = model.FFinancePropNo;
            parameters[10].Value = model.FYear;
            parameters[11].Value = model.FStatus;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters;
            cmdList.Add(cmds);

            foreach (Model.AllowanceFileEntry enModel in enList)
            {
                cmds = new CommandInfo();
                var getBillIdSql2 = "exec sp_getbillno 'fund.t_AllowanceFileEntry','FAllowanceFileEntryID','','','',@returnBId2 output ";
                var getBillIdPar2 = new SqlParameter[]{ 
                new SqlParameter("@returnBId2", SqlDbType.NVarChar, 50)
                };

                getBillIdPar2[0].Direction = ParameterDirection.Output;

                cmds.CommandText = getBillIdSql2.ToString();
                cmds.Parameters = getBillIdPar2;
                cmdList.Add(cmds);

                cmds = new CommandInfo();
                strSql = new StringBuilder();
                strSql.Append("insert into fund.t_AllowanceFileEntry(");
                strSql.Append("FAllowanceFileEntryID,FAllowanceFileID,NSRDZDAH,FAmount,FNote)");
                strSql.Append(" values (");
                strSql.Append("@returnBId2,@returnBId,@NSRDZDAH,@FAmount,@FNote)");
                SqlParameter[] parameters2 = {
					new SqlParameter("@returnBId2", SqlDbType.NVarChar,50),
					new SqlParameter("@returnBId", SqlDbType.NVarChar,50),
					new SqlParameter("@NSRDZDAH", SqlDbType.Decimal,13),
					new SqlParameter("@FAmount", SqlDbType.Decimal,13),
					new SqlParameter("@FNote", SqlDbType.NVarChar,255)};
                parameters2[0].Direction = ParameterDirection.InputOutput;
                parameters2[1].Direction = ParameterDirection.InputOutput;
                parameters2[2].Value = enModel.NSRDZDAH;
                parameters2[3].Value = enModel.FAmount;
                parameters2[4].Value = enModel.FNote;
                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters2;
                cmdList.Add(cmds);

                cmds = new CommandInfo();
                strSql = new StringBuilder();
                strSql.Append(@"UPDATE fund.t_AllowanceIssueEntry SET FAllowanceFileEntryID =@returnBId2
WHERE FIssueID IN (" + issueIDList + @") AND NSRDZDAH=@NSRDZDAH and FAllowanceIssueEntryID in (SELECT FAllowanceIssueEntryID  FROM [fund].[t_AllowanceIssueEntry] AS a
 LEFT JOIN fund.t_TaxAuditPolicyEval AS b ON a.FIssueID=b.FIssueID AND a.FTaxClassAllowanceNo=b.FTaxClassAllowanceNo
 WHERE b.FFinancePropNo=@FFinancePropNo)");
                SqlParameter[] parameters3 = { 
					new SqlParameter("@returnBId2", SqlDbType.NVarChar,50),
					new SqlParameter("@NSRDZDAH", SqlDbType.Decimal,13),
					new SqlParameter("@FFinancePropNo", SqlDbType.NVarChar,50)};
                parameters3[0].Direction = ParameterDirection.InputOutput;
                parameters3[1].Value = enModel.NSRDZDAH;
                parameters3[2].Value = model.FFinancePropNo;
                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters3;
                cmdList.Add(cmds);

                cmds = new CommandInfo();
                strSql = new StringBuilder();
                strSql.Append(@"UPDATE fund.t_SpecificAdjust SET FAllowanceFileEntryID =@returnBId2
WHERE FIssueID IN (" + issueIDList + ") AND NSRDZDAH=@NSRDZDAH and FFinancePropNo=@FFinancePropNo ");
                SqlParameter[] parameters4 = {
					new SqlParameter("@returnBId2", SqlDbType.NVarChar,50),
					new SqlParameter("@NSRDZDAH", SqlDbType.Decimal,13),
					new SqlParameter("@FFinancePropNo", SqlDbType.NVarChar,50)};
                parameters4[0].Direction = ParameterDirection.InputOutput;
                parameters4[1].Value = enModel.NSRDZDAH;
                parameters4[2].Value = model.FFinancePropNo;
                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters4;
                cmdList.Add(cmds);

            }

            
            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithCommonList(cmdList);
            }

            return parameters[0].Value.ToString();
        }

        /// <summary>
        /// 增加文件
        /// </summary>
        /// <param name="enList"></param>
        /// <param name="model"></param>
        public void UpdateFile(List<Model.AllowanceFileEntry> enList, Model.AllowanceFile model, string issueIDList)
        {
            StringBuilder strSql = new StringBuilder();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();

            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("update fund.t_AllowanceFile set ");
            strSql.Append("FPeriod=@FPeriod,");
            strSql.Append("FNote=@FNote,");
            strSql.Append("FUpdEmplNo=@FUpdEmplNo,");
            strSql.Append("FUpdDeptNo=@FUpdDeptNo,");
            strSql.Append("FUpdDate=@FUpdDate,");
            strSql.Append("FUpdIP=@FUpdIP,");
            strSql.Append("FStatus=@FStatus,");
            strSql.Append("FIsReturn=@FIsReturn");
            strSql.Append(" where FAllowanceFileID=@FAllowanceFileID ");
            SqlParameter[] parameters = {
					new SqlParameter("@FPeriod", SqlDbType.Int,4),
					new SqlParameter("@FNote", SqlDbType.NVarChar,255),
					new SqlParameter("@FUpdEmplNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FUpdDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FUpdDate", SqlDbType.DateTime),
					new SqlParameter("@FUpdIP", SqlDbType.VarChar,15),
					new SqlParameter("@FStatus", SqlDbType.NVarChar,6),
					new SqlParameter("@FIsReturn", SqlDbType.NVarChar,1),
					new SqlParameter("@FAllowanceFileID", SqlDbType.NVarChar,50)};
            parameters[0].Value = model.FPeriod;
            parameters[1].Value = model.FNote;
            parameters[2].Value = model.FUpdEmplNo;
            parameters[3].Value = model.FUpdDeptNo;
            parameters[4].Value = model.FUpdDate;
            parameters[5].Value = model.FUpdIP;
            parameters[6].Value = model.FStatus;
            parameters[7].Value = model.FIsReturn;
            parameters[8].Value = model.FAllowanceFileID;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters;
            cmdList.Add(cmds);


            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("update fund.t_AllowanceIssueEntry set FAllowanceFileEntryID = null where FAllowanceFileEntryID in (SELECT FAllowanceFileEntryID FROM fund.t_AllowanceFileEntry");
            strSql.Append(" where FAllowanceFileID=@FAllowanceFileID )");
            SqlParameter[] parameters7 = {
					new SqlParameter("@FAllowanceFileID", SqlDbType.NVarChar,50)};
            parameters7[0].Value = model.FAllowanceFileID;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters7;
            cmdList.Add(cmds);

            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("delete from fund.t_AllowanceFileEntry  ");
            strSql.Append(" where FAllowanceFileID=@FAllowanceFileID ");
            SqlParameter[] parameters6 = {
					new SqlParameter("@FAllowanceFileID", SqlDbType.NVarChar,50)};
            parameters6[0].Value = model.FAllowanceFileID;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters6;
            cmdList.Add(cmds);

            foreach (Model.AllowanceFileEntry enModel in enList)
            {
                cmds = new CommandInfo();
                var getBillIdSql2 = "exec sp_getbillno 'fund.t_AllowanceFileEntry','FAllowanceFileEntryID','','','',@returnBId2 output ";
                var getBillIdPar2 = new SqlParameter[]{ 
                new SqlParameter("@returnBId2", SqlDbType.NVarChar, 50)
                };

                getBillIdPar2[0].Direction = ParameterDirection.Output;

                cmds.CommandText = getBillIdSql2.ToString();
                cmds.Parameters = getBillIdPar2;
                cmdList.Add(cmds);

                cmds = new CommandInfo();
                strSql = new StringBuilder();
                strSql.Append("insert into fund.t_AllowanceFileEntry(");
                strSql.Append("FAllowanceFileEntryID,FAllowanceFileID,NSRDZDAH,FAmount,FNote)");
                strSql.Append(" values (");
                strSql.Append("@returnBId2,@returnBId,@NSRDZDAH,@FAmount,@FNote)");
                SqlParameter[] parameters2 = {
					new SqlParameter("@returnBId2", SqlDbType.NVarChar,50),
					new SqlParameter("@returnBId", SqlDbType.NVarChar,50),
					new SqlParameter("@NSRDZDAH", SqlDbType.Decimal,13),
					new SqlParameter("@FAmount", SqlDbType.Decimal,13),
					new SqlParameter("@FNote", SqlDbType.NVarChar,255)};
                parameters2[0].Direction = ParameterDirection.InputOutput;
                parameters2[1].Value = model.FAllowanceFileID;
                parameters2[2].Value = enModel.NSRDZDAH;
                parameters2[3].Value = enModel.FAmount;
                parameters2[4].Value = enModel.FNote;
                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters2;
                cmdList.Add(cmds);

                cmds = new CommandInfo();
                strSql = new StringBuilder();
                strSql.Append(@"UPDATE fund.t_AllowanceIssueEntry SET FAllowanceFileEntryID =@returnBId2
WHERE FIssueID IN (" + issueIDList + @") AND NSRDZDAH=@NSRDZDAH and FAllowanceIssueEntryID in (SELECT FAllowanceIssueEntryID  FROM [fund].[t_AllowanceIssueEntry] AS a
 LEFT JOIN fund.t_TaxAuditPolicyEval AS b ON a.FIssueID=b.FIssueID AND a.FTaxClassAllowanceNo=b.FTaxClassAllowanceNo
 WHERE b.FFinancePropNo=@FFinancePropNo)");
                SqlParameter[] parameters3 = { 
					new SqlParameter("@returnBId2", SqlDbType.NVarChar,50),
					new SqlParameter("@NSRDZDAH", SqlDbType.Decimal,13),
					new SqlParameter("@FFinancePropNo", SqlDbType.NVarChar,50)};
                parameters3[0].Direction = ParameterDirection.InputOutput;
                parameters3[1].Value = enModel.NSRDZDAH;
                parameters3[2].Value = model.FFinancePropNo;
                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters3;
                cmdList.Add(cmds);

                cmds = new CommandInfo();
                strSql = new StringBuilder();
                strSql.Append(@"UPDATE fund.t_SpecificAdjust SET FAllowanceFileEntryID =@returnBId2
WHERE FIssueID IN (" + issueIDList + ") AND NSRDZDAH=@NSRDZDAH and FFinancePropNo=@FFinancePropNo ");
                SqlParameter[] parameters4 = {
					new SqlParameter("@returnBId2", SqlDbType.NVarChar,50),
					new SqlParameter("@NSRDZDAH", SqlDbType.Decimal,13),
					new SqlParameter("@FFinancePropNo", SqlDbType.NVarChar,50)};
                parameters4[0].Direction = ParameterDirection.InputOutput;
                parameters4[1].Value = enModel.NSRDZDAH;
                parameters4[2].Value = model.FFinancePropNo;
                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters4;
                cmdList.Add(cmds);

            }


            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithCommonList(cmdList);
            }
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(EnterpriseFund.Model.AllowanceFile model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update fund.t_AllowanceFile set ");
            strSql.Append("FFileNo=@FFileNo,");
            strSql.Append("FFileTransDate=@FFileTransDate,");
            strSql.Append("FNote=@FNote,");
            strSql.Append("FStatus=2");
            strSql.Append(" where FAllowanceFileID=@FAllowanceFileID ");
            SqlParameter[] parameters = {
					new SqlParameter("@FFileNo", SqlDbType.NVarChar,255),
					new SqlParameter("@FFileTransDate", SqlDbType.DateTime),
					new SqlParameter("@FNote", SqlDbType.NVarChar,255),
					new SqlParameter("@FAllowanceFileID", SqlDbType.NVarChar,50)};
            parameters[0].Value = model.FFileNo;
            parameters[1].Value = model.FFileTransDate;
            parameters[2].Value = model.FNote;
            parameters[3].Value = model.FAllowanceFileID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public void Delete(string FAllowanceFileID)
        {
            StringBuilder strSql = new StringBuilder();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();

            strSql = new StringBuilder();
            strSql.Append("UPDATE fund.t_AllowanceIssueEntry SET FAllowanceFileEntryID = null ");
            strSql.Append(" where FAllowanceFileEntryID in (select FAllowanceFileEntryID from fund.t_AllowanceFileEntry where FAllowanceFileID = @FAllowanceFileID) ");
            SqlParameter[] parameters3 = {
					new SqlParameter("@FAllowanceFileID", SqlDbType.NVarChar,50)			};
            parameters3[0].Value = FAllowanceFileID;

            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters3;
            cmdList.Add(cmds);

            cmds = new CommandInfo();

            strSql = new StringBuilder();
            strSql.Append("UPDATE fund.t_SpecificAdjust SET FAllowanceFileEntryID = null ");
            strSql.Append(" where FAllowanceFileEntryID in (select FAllowanceFileEntryID from fund.t_AllowanceFileEntry where FAllowanceFileID = @FAllowanceFileID) ");
            SqlParameter[] parameters5 = {
					new SqlParameter("@FAllowanceFileID", SqlDbType.NVarChar,50)			};
            parameters3[0].Value = FAllowanceFileID;

            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters5;
            cmdList.Add(cmds);

            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("delete from fund.t_AllowanceFileEntry ");
            strSql.Append(" where FAllowanceFileID=@FAllowanceFileID ");
            SqlParameter[] parameters = {
					new SqlParameter("@FAllowanceFileID", SqlDbType.NVarChar,50)			};
            parameters[0].Value = FAllowanceFileID;

            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters;
            cmdList.Add(cmds);

            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("delete from fund.t_AllowanceFile ");
            strSql.Append(" where FAllowanceFileID=@FAllowanceFileID ");
            SqlParameter[] parameters2 = {
					new SqlParameter("@FAllowanceFileID", SqlDbType.NVarChar,50)			};
            parameters2[0].Value = FAllowanceFileID;

            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters2;
            cmdList.Add(cmds);

            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithCommonList(cmdList);
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public DataSet GetFIssueIDByFAllowanceFileID(string FAllowanceFileID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"SELECT  
       DISTINCT FIssueID 
 FROM fund.t_AllowanceIssueEntry WHERE FAllowanceFileEntryID IN ( SELECT FAllowanceFileEntryID FROM fund.t_AllowanceFileEntry  where FAllowanceFileID=@FAllowanceFileID )");
            SqlParameter[] parameters = {
					new SqlParameter("@FAllowanceFileID", SqlDbType.NVarChar,50)			};
            parameters[0].Value = FAllowanceFileID;

           
            return DbHelperSQL.Query(strSql.ToString(), parameters);

        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public EnterpriseFund.Model.AllowanceFile GetModel(string FAllowanceFileID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FAllowanceFileID,FPeriod,FFileName,FFileNo,FFileTransDate,FNote,FEntityNo,FInsEmpNo,FInsDeptNo,FInsDate,FInsIP,FUpdEmplNo,FUpdDeptNo,FUpdDate,FUpdIP,FFinancePropNo,FYear,FStatus from fund.t_AllowanceFile ");
            strSql.Append(" where FAllowanceFileID=@FAllowanceFileID ");
            SqlParameter[] parameters = {
					new SqlParameter("@FAllowanceFileID", SqlDbType.NVarChar,50)			};
            parameters[0].Value = FAllowanceFileID;

            EnterpriseFund.Model.AllowanceFile model = new EnterpriseFund.Model.AllowanceFile();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            { 
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public EnterpriseFund.Model.AllowanceFile DataRowToModel(DataRow row)
        {
            EnterpriseFund.Model.AllowanceFile model = new EnterpriseFund.Model.AllowanceFile();
            if (row != null)
            {
                if (row["FAllowanceFileID"] != null)
                {
                    model.FAllowanceFileID = row["FAllowanceFileID"].ToString();
                }
                if (row["FPeriod"] != null && row["FPeriod"].ToString() != "")
                {
                    model.FPeriod = int.Parse(row["FPeriod"].ToString());
                }
                if (row["FFileName"] != null)
                {
                    model.FFileName = row["FFileName"].ToString();
                }
                if (row["FFileNo"] != null)
                {
                    model.FFileNo = row["FFileNo"].ToString();
                }
                if (row["FFileTransDate"] != null && row["FFileTransDate"].ToString() != "")
                {
                    model.FFileTransDate = DateTime.Parse(row["FFileTransDate"].ToString());
                }
                if (row["FNote"] != null)
                {
                    model.FNote = row["FNote"].ToString();
                }
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
                if (row["FInsEmpNo"] != null)
                {
                    model.FInsEmpNo = row["FInsEmpNo"].ToString();
                }
                if (row["FInsDeptNo"] != null)
                {
                    model.FInsDeptNo = row["FInsDeptNo"].ToString();
                }
                if (row["FInsDate"] != null && row["FInsDate"].ToString() != "")
                {
                    model.FInsDate = DateTime.Parse(row["FInsDate"].ToString());
                }
                if (row["FInsIP"] != null)
                {
                    model.FInsIP = row["FInsIP"].ToString();
                }
                if (row["FUpdEmplNo"] != null)
                {
                    model.FUpdEmplNo = row["FUpdEmplNo"].ToString();
                }
                if (row["FUpdDeptNo"] != null)
                {
                    model.FUpdDeptNo = row["FUpdDeptNo"].ToString();
                }
                if (row["FUpdDate"] != null && row["FUpdDate"].ToString() != "")
                {
                    model.FUpdDate = DateTime.Parse(row["FUpdDate"].ToString());
                }
                if (row["FUpdIP"] != null)
                {
                    model.FUpdIP = row["FUpdIP"].ToString();
                }
                if (row["FFinancePropNo"] != null)
                {
                    model.FFinancePropNo = row["FFinancePropNo"].ToString();
                }
                if (row["FYear"] != null && row["FYear"].ToString() != "")
                {
                    model.FYear = decimal.Parse(row["FYear"].ToString());
                }
                if (row.Table.Columns.Contains("sumFAmount"))
                {
                    if (row["sumFAmount"] != null && row["sumFAmount"].ToString() != "")
                    {
                        model.sumFAmount = decimal.Parse(row["sumFAmount"].ToString());
                    }
                }
                if (row.Table.Columns.Contains("FStatus"))
                {
                    if (row["FStatus"] != null && row["FStatus"].ToString() != "")
                    {
                        model.FStatus = row["FStatus"].ToString();
                    }
                }
                
            }
            return model;
        }

        public string GetJe(string FSource, string FAllowanceFileID, string NSRDZDAH)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"   select sumFAmount FROM fund.[v_ALLAllowanceFile] WHERE FSource='" + FSource + "' AND FAllowanceFileID='" + FAllowanceFileID + "' and NSRDZDAH= " + NSRDZDAH);
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj != null)
            {
                return obj.ToString();
            }
            else
            {
                return "";
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetCboList(string NSRDZDAH)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"SELECT  FSource ,
        FAllowanceFileID ,
        FFileName ,
        FFileNo ,
        a.FFinancePropNo ,d.FFinancePropName FROM fund.v_ALLAllowanceFile a LEFT JOIN fund.t_FinanceProp d ON a.FFinancePropNo = d.FFinancePropNo WHERE 
 FAllowanceFileID IN (SELECT FAllowanceFileID FROM fund.v_ALLAllowanceFileEntry b WHERE b.NSRDZDAH='" + NSRDZDAH + @"' AND a.FSource = b.FSource) 
        AND FAllowanceFileID NOT IN (SELECT FSourceNo FROM fund.t_AllowanceApplicationForm c WHERE NSRDZDAH='" + NSRDZDAH + @"' AND a.FSource = c.FSource) and      
  NSRDZDAH=" + NSRDZDAH + @" and FFileNo is not null
                        ");
            return DbHelperSQL.Query(strSql.ToString());
        }

        public bool VerifyFile(string fAllowanceFileID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"    SELECT count(*) FROM  fund.t_AllowanceFile a where
    FAllowanceFileID NOT IN (SELECT FSourceNo 
        FROM fund.t_AllowanceApplicationForm c WHERE
          c.FSource ='A' )  AND FAllowanceFileID='" + fAllowanceFileID + "'");
            object i = DbHelperSQL.GetSingle(strSql.ToString());
            if (i != null)
            {
                if (int.Parse(i.ToString()) == 0)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FAllowanceFileID,FPeriod,FFileName,FFileNo,FFileTransDate,FNote,FEntityNo,FInsEmpNo,FInsDeptNo,FInsDate,FInsIP,FUpdEmplNo,FUpdDeptNo,FUpdDate,FUpdIP,FFinancePropNo,FYear ");
            strSql.Append(" FROM fund.t_AllowanceFile ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" FAllowanceFileID,FPeriod,FFileName,FFileNo,FFileTransDate,FNote,FEntityNo,FInsEmpNo,FInsDeptNo,FInsDate,FInsIP,FUpdEmplNo,FUpdDeptNo,FUpdDate,FUpdIP,FFinancePropNo,FYear ");
            strSql.Append(" FROM fund.t_AllowanceFile ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取最大批号
        /// </summary>
        public int GetMaxPeriod(string year, string FFinancePropNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT (ISNULL(MAX(FPeriod),0)+1) AS FPeriod FROM fund.t_AllowanceFile WHERE FYear='" + year + "' and FFinancePropNo='" + FFinancePropNo + "'");
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM fund.t_AllowanceFile ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.FAllowanceFileID desc");
            }
            strSql.Append(")AS Row, T.*  from fund.t_AllowanceFile T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "t_AllowanceFile";
            parameters[1].Value = "FAllowanceFileID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

